<!DOCTYPE html>
<html lang="zh-CN">
<meta charset="utf-8" />
<head>
<title>添加行业 <?php echo $this->config->item('title');?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="<?php echo base_url()?>public/css/bootstrap.min.css">
<link rel="stylesheet" href="<?php echo base_url()?>public/css/style.css">
<script src="<?php echo base_url()?>public/js/jquery-2.0.2.min.js"></script>
<script src="<?php echo base_url()?>public/js/bootstrap.min.js"></script>
<script src="<?php echo base_url()?>public/js/bootstrap-confirm.js"></script>
<script src='<?php echo base_url()?>public/js/jquery.form.js'></script>
<script src="<?php echo base_url()?>public/js/ssi_common.js"></script>


</head>
<body>
	<div role="navigation" class="navbar navbar-inverse navbar-fixed-top">
		<div class="container">
			<div class="navbar-header">
				<a class="navbar-brand">SSI后台管理系统</a>
			</div>
			<div class="collapse navbar-collapse navbar-right">
				<ul class="nav navbar-nav">
					<li><a href="<?php echo base_url()?>" class="navbar-link">首页</a></li>
					<li><a href="<?php echo base_url()."index.php/common_login_user_set"?>" class="navbar-link">超级管理员</a></li>
					<li><a href="<?php echo base_url()?>index.php/common_login_manage/logout" class="navbar-link">退出</a></li>
				</ul>
			</div>
		</div>
	</div>
	<div class="container">
	
		<div class="row">
			<div class="col-xs-3">
				<?php echo $user_menu?>
			</div>
			<div class="alert alert-danger alert-dismissable" style="display: none;">
			<button type="button" data-dismiss="alert" aria-hidden="true" class="close">&times;</button>
			<div class="text-center" id="error_message"></div>
			</div>
			<div class="col-md-9">
				<div class="panel panel-default">
					<div class="panel-heading">添加行业</div>
					<div class="panel-body">
						<form method="post" enctype="multipart/form-data" id="ssi_main_form" action="<?php echo base_url()."index.php/sys_industry_manage/save_industry"?>"
							class="form-horizontal">
							<div class="form-group">
								<label for="parent1" class="control-label col-sm-2">上级行业</label>
								<div id="parents" class="col-sm-5">
									<select id="parent1" name="parent1"   class="form-control">
										<option	value="0">无</option>
										<?php foreach ($top_industrys as $industry){?>
										<option value="<?php echo $industry['industry_id']?>"><?php echo $industry['industry_name']?></option>
										<?php }?>
									</select>
								</div>
							</div>
							<div id="Name" class="form-group">
								<label for="name" class="control-label col-sm-2">名称</label>
								<div class="col-sm-5">
									<input id="name" type="text" name="industry_name" class="form-control">
								</div>
							</div>
							
							<div class="form-group">
								<div class="col-sm-offset-2 col-sm-5">
									<button type="submit" class="btn btn-primary">添加</button>
									<a href="javascript:void()" onclick='history.back()' >返回</a>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
<script>
function showErrorIf(condition, groupid, errmsg) {
	 var group = $("#" + groupid);
	 $("#" + groupid + ' .help-block').remove();
	 if (condition) {
	  group.append("<span class='help-block'>" + errmsg + "</span>");
	  group.addClass('has-error');
	 } else {
	  group.removeClass('has-error');
	 }
	}
	function checkName() {
	 var name = $('#name').val();
	 showErrorIf(name.length == 0, 'Name', '必须填写行业名称');
	}
	$(function($) {
	 $("form").submit(function(e){
	  checkName();
	  var errors = $('.form-group.has-error');
	  if (errors.length > 0) {
	   e.preventDefault();
	   return;
	  }
	  $('button[type="submit"]').addClass('disabled');
	 });
});	

</script>
<script type="text/javascript">
jQuery(function() {
	$("#parents").on('change',"#parent2",function(){
		if($("#parent2").get(0).selectedIndex!="0"){
			$("#industry_type_div").show();
		}else{
			$("#industry_type_div").hide();
		}
	});

	$('#ssi_main_form').ajaxForm({
		dataType:  'json',
		beforeSubmit:  showRequest,
		success:   processJson
	});

	function showRequest(formData, jqForm, options) {
		$(".alert").hide(400);
	}

	function processJson(data) {
		if (data.result==false) {
			$(".alert").show(400);
			$("#error_message").text(data.message);
		}else{
			window.location.href=data.redirect_url;
		}
	}
});
</script>

<div  class="back-to" id="toolBackTop">
	<a title="返回顶部" onclick="window.scrollTo(0,0);return false;" href="#top" class="back-top">
	返回顶部</a>
	<a title="返回底部" onclick="window.scrollTo(0,document.body.scrollHeight);return false;" href="#bottom" class="back-bottom">
	返回底部</a>
</div>
</html>
